
#include <BVBoxLayout>
#include <BHBoxLayout>
#include <BGridLayout>
#include <BLabel>
#include <BTreeItem>
#include <BEntry>

#include "PropertyBoard.h"

PropertyBoard::PropertyBoard(BWidget* parent) : BGroupBox(parent)
{
	this->setTitle("Property");

	BGridLayout* gridLayout = new BGridLayout();
	{
		_nameLineEdit = new BLineEdit();
		_typeLineEdit = new BLineEdit();
		_pathLineEdit = new BLineEdit();
		_sizeSpinBox = new BLongSpinBox();
		_sizeSpinBox->setReadOnly(true);
		_sizeSpinBox->setSuffix("KB");
		gridLayout->addWidget(0, 0, new BLabel("name"));
		gridLayout->addWidget(0, 1, _nameLineEdit);
		gridLayout->addWidget(1, 0, new BLabel("type"));
		gridLayout->addWidget(1, 1, _typeLineEdit);
		gridLayout->addWidget(2, 0, new BLabel("path"));
		gridLayout->addWidget(2, 1, _pathLineEdit);
		gridLayout->addWidget(3, 0, new BLabel("size"));
		gridLayout->addWidget(3, 1, _sizeSpinBox);
		gridLayout->setColumnStretch(0, 0);
	}
	BVBoxLayout* vlayout = new BVBoxLayout(this);
	vlayout->addLayout(gridLayout);
	vlayout->addSpring();

	connect(this, Signal_AssetChanged, &PropertyBoard::slotAssetChanged);

}
PropertyBoard::~PropertyBoard()
{

}


void PropertyBoard::slotAssetChanged(BObject* object, const BValue& value)
{
	if (BTreeItem* item = value)
	{
		_nameLineEdit->setText(item->text());
		if (BEntry* entry = item->asset())
		{
			if (entry->attrib() & Attrib_File)
				_typeLineEdit->setText("file");
			else
				_typeLineEdit->setText("folder");
			_sizeSpinBox->setValue(entry->size());
		}
		else
		{
			_typeLineEdit->setText("filter");
			_sizeSpinBox->setValue(0);
		}
		_pathLineEdit->setText(item->property("path"));
	}
	else
	{
		_nameLineEdit->setText(BString());
		_typeLineEdit->setText(BString());
		_sizeSpinBox->setValue(0);
		_pathLineEdit->setText(BString());
	}
}
